//package com.breakfast.fun.adapter.user;
//
//import android.content.Context;
//import android.content.Intent;
//import android.net.Uri;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.LinearLayout;
//import android.widget.RelativeLayout;
//import android.widget.TextView;
//
//import com.breakfast.fun.Constant;
//import com.breakfast.fun.R;
//import com.breakfast.fun.base.BaseListAdapter;
//import com.breakfast.fun.data.entity.user.address.BuildingData;
//import com.breakfast.fun.event.FinishEvent;
//import com.breakfast.fun.util.L;
//import com.breakfast.fun.view.widget.CustomDialog;
//
//import org.greenrobot.eventbus.EventBus;
//
//import java.util.List;
//
//import butterknife.Bind;
//import butterknife.ButterKnife;
//
///**
// * Created by yukai on 16/9/16.
// */
//public class ChooseBuildingAdapter extends BaseListAdapter<BuildingData> {
//    private static boolean isOpened = true;
//    private CustomDialog dialog = null;
//
//    public ChooseBuildingAdapter(Context context){
//        super(context);
//
//    }
//    public ChooseBuildingAdapter(Context context, List<BuildingData> list) {
//        super(context, list);
//    }
//
//    @Override
//    public View getView(int position, View convertView, ViewGroup parent) {
//        final ViewHolder holder;
//        if (convertView == null) {
//            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_choose_area, null);
//            holder = new ViewHolder(convertView);
//            convertView.setTag(holder);
//        } else {
//            holder = (ViewHolder) convertView.getTag();
//        }
//        BuildingData data = getItem(position);
//        holder.mTvItemChooseArea.setText(data.getBuilderName());
//
//        holder.mTvChooseAddress.setText(data.getAddress());
//        holder.mLlItemChooseArea.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(isOpened) {
//                    EventBus.getDefault().post(new FinishEvent("ChooseBuildingActivity"));
//                    EventBus.getDefault().post(data);
//                }else{
//                    dialog = new CustomDialog(mContext, R.style.dialog_style,
//                            R.layout.dialog_custom, "已选择的大楼未开通配送服务", "是否咨询客服?", false,false, new View.OnClickListener() {
//                        @Override
//                        public void onClick(View view) {
//                            dialog.dismiss();
//                            Intent intent = new Intent();
//                            Uri uri = Uri.parse("tel:" + Constant.SERVICE_TEL);
//                            intent = new Intent(Intent.ACTION_DIAL, uri);
//                            mContext.startActivity(intent);
//                        }
//                    });
//                    dialog.show();
//                }
//            }
//        });
//
//        return convertView;
//    }
//
//    public void setOpened(boolean opened) {
//        isOpened = opened;
//    }
//
//    public boolean getOpened(){return isOpened;}
//    static class ViewHolder {
//        @Bind(R.id.tv_item_choose_area)
//        TextView mTvItemChooseArea;
//        @Bind(R.id.ll_item_choose_area)
//        RelativeLayout mLlItemChooseArea;
//        @Bind(R.id.tv_choose_address)
//        TextView mTvChooseAddress;
//        ViewHolder(View view) {
//            ButterKnife.bind(this, view);
//        }
//    }
//}
package com.breakfast.fun.adapter.user;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.breakfast.fun.R;
import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.user.address.BuildingData;
import com.breakfast.fun.event.FinishEvent;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by yukai on 16/9/16.
 */
public class ChooseBuildingAdapter extends BaseListAdapter<BuildingData> {
    public ChooseBuildingAdapter(Context context, List<BuildingData> list) {
        super(context, list);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_choose_area, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BuildingData data = getItem(position);
        holder.mTvItemChooseArea.setText(data.getBuilderName());

        holder.mLlItemChooseArea.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new FinishEvent("ChooseBuildingActivity"));
                EventBus.getDefault().post(data);
            }
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_item_choose_area)
        TextView mTvItemChooseArea;
        @Bind(R.id.ll_item_choose_area)
        LinearLayout mLlItemChooseArea;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
